home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / sun / volume1 / dgtool < prev    next >
Encoding:
Text File  |  1989-07-20  |  28.3 KB  |  1,129 lines

  1. Path: uunet!wyse!vsi1!apple!sun-barr!rutgers!aramis.rutgers.edu!dartagnan.rutgers.edu!mcgrew
  2. From: mcgrew@dartagnan.rutgers.edu (Charles Mcgrew)
  3. Newsgroups: comp.sources.sun
  4. Subject: v01i050:  DGtool - Data General terminal emulator
  5. Message-ID: <Jul.20.17.07.57.1989.17170@dartagnan.rutgers.edu>
  6. Date: 20 Jul 89 21:08:00 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 1118
  9. Approved: mcgrew@aramis.rutgers.edu
  10.  
  11. Submitted-by: ksp@maxwell.nde.swri.edu
  12. Posting-number: Volume 1, Issue 50
  13. Archive-name: dgtool
  14.  
  15. #!/bin/sh
  16. # This is a shell archive, meaning:
  17. # 1. Remove everything above the #!/bin/sh line.
  18. # 2. Save the resulting text in a file.
  19. # 3. Execute the file with /bin/sh (not csh) to create the files:
  20. #    README
  21. #    COPYRIGHT
  22. #    Makefile
  23. #    dg.1
  24. #    dg.c
  25. #    dgtool.1
  26. #    dgtool.c
  27. #    dgtool.icon
  28. # This archive created: Fri Jun 30 08:54:06 1989
  29. export PATH; PATH=/bin:$PATH
  30. echo shar: extracting "'README'" '(560 characters)'
  31. if test -f 'README'
  32. then
  33.     echo shar: over-writing existing file "'README'"
  34. fi
  35. sed 's/^X//' << \SHAR_EOF > 'README'
  36. X
  37. XThis is a very simple dg terminal emulator. At this time
  38. X(30 June 1989) it provides a d460 type of function key
  39. Xsupport and a d6053 type of screen emulation.
  40. X
  41. XChanges and enhancements to the code are encouraged.
  42. X
  43. XPlease mail a copy of fixes or enhancements to:
  44. X
  45. Xksp@maxwell.nde.swri.edu
  46. X
  47. XNotes:
  48. X    You will need to change the path at the top of
  49. X    dgtool.c to the path you will use for `dg'.
  50. X
  51. X
  52. X        Good luck,
  53. X
  54. X          -keith
  55. X
  56. XKeith S. Pickens           Southwest Research Institute
  57. Xksp@maxwell.nde.swri.edu
  58. X{sun!texsun, gatech!petro, cs.utexas.edu}!swrinde!maxwell!ksp
  59. SHAR_EOF
  60. if test 560 -ne "`wc -c 'README'`"
  61. then
  62.     echo shar: error transmitting "'README'" '(should have been 560 characters)'
  63. fi
  64. echo shar: extracting "'COPYRIGHT'" '(766 characters)'
  65. if test -f 'COPYRIGHT'
  66. then
  67.     echo shar: over-writing existing file "'COPYRIGHT'"
  68. fi
  69. sed 's/^X//' << \SHAR_EOF > 'COPYRIGHT'
  70. X
  71. XCopyright (c) 1989 Southwest Research Institute
  72. XAll rights reserved.
  73. X
  74. XRedistribution and use in source and binary forms are permitted
  75. Xprovided that the above copyright notice and this paragraph are
  76. Xduplicated in all such forms and that any documentation,
  77. Xadvertising materials, and other materials related to such
  78. Xdistribution and use acknowledge that the software was developed
  79. Xby Southwest Research Institute.  The name of Southwest Research
  80. XInstitute may not be used to endorse or promote products derived
  81. Xfrom this software without specific prior written permission.
  82. XTHIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  83. XIMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  84. XWARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  85. SHAR_EOF
  86. if test 766 -ne "`wc -c 'COPYRIGHT'`"
  87. then
  88.     echo shar: error transmitting "'COPYRIGHT'" '(should have been 766 characters)'
  89. fi
  90. echo shar: extracting "'Makefile'" '(187 characters)'
  91. if test -f 'Makefile'
  92. then
  93.     echo shar: over-writing existing file "'Makefile'"
  94. fi
  95. sed 's/^X//' << \SHAR_EOF > 'Makefile'
  96. XCFLAGS= -O
  97. XLDFLAGS= 
  98. X
  99. Xall: dg dgtool
  100. X
  101. Xdg: dg.o
  102. X    cc ${LDFLAGS} -o dg dg.o
  103. X
  104. Xdgtool: dgtool.o
  105. X     cc ${LDFLAGS} -o dgtool dgtool.o -lsuntool -lsunwindow -lpixrect
  106. X
  107. Xclean:
  108. X    rm -f *.o dg dgtool
  109. SHAR_EOF
  110. if test 187 -ne "`wc -c 'Makefile'`"
  111. then
  112.     echo shar: error transmitting "'Makefile'" '(should have been 187 characters)'
  113. fi
  114. echo shar: extracting "'dg.1'" '(1461 characters)'
  115. if test -f 'dg.1'
  116. then
  117.     echo shar: over-writing existing file "'dg.1'"
  118. fi
  119. sed 's/^X//' << \SHAR_EOF > 'dg.1'
  120. X.\" Copyright (c) 1989 Southwest Research Institute
  121. X.\" All rights reserved.
  122. X.\"
  123. X.\" Redistribution and use in source and binary forms are permitted
  124. X.\" provided that the above copyright notice and this paragraph are
  125. X.\" duplicated in all such forms and that any documentation,
  126. X.\" advertising materials, and other materials related to such
  127. X.\" distribution and use acknowledge that the software was developed
  128. X.\" by Southwest Research Institute.  The name of Southwest Research
  129. X.\" Institute may not be used to endorse or promote products derived
  130. X.\" from this software without specific prior written permission.
  131. X.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  132. X.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  133. X.\" WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  134. X.\"
  135. X.TH DG 1L "30 June 1989"
  136. X.SH NAME
  137. Xdg\- provide a Data General terminal emulation
  138. X.SH SYNOPSIS
  139. X.B dg
  140. X.I serial line
  141. X[
  142. X.I baud rate
  143. X]
  144. X.SH DESCRIPTION
  145. X.I dg
  146. Xprovides a serial line
  147. Xinterface for a Data General system.
  148. X.I dg
  149. Xonly provides cursor motion emulation for the common DG 6053
  150. Xcommands.
  151. XIt is not complete.
  152. X.SH OPTIONS
  153. X.LP
  154. XThe first argument of
  155. X.I dg
  156. Xspecifies which serial line to use when accessing the DG.
  157. XThe second argument is optional and specifies the baud rate to
  158. Xbe used in communicating with the DG.
  159. XIf no baud rate is given 9600 is used.
  160. X.SH "SEE ALSO"
  161. Xdgtool(1L)
  162. X.SH AUTHOR
  163. XKeith S. Pickens, Southwest Research Institute
  164. SHAR_EOF
  165. if test 1461 -ne "`wc -c 'dg.1'`"
  166. then
  167.     echo shar: error transmitting "'dg.1'" '(should have been 1461 characters)'
  168. fi
  169. echo shar: extracting "'dg.c'" '(7795 characters)'
  170. if test -f 'dg.c'
  171. then
  172.     echo shar: over-writing existing file "'dg.c'"
  173. fi
  174. sed 's/^X//' << \SHAR_EOF > 'dg.c'
  175. X/*
  176. X * Copyright (c) 1989 Southwest Research Institute
  177. X * All rights reserved.
  178. X *
  179. X * Redistribution and use in source and binary forms are permitted
  180. X * provided that the above copyright notice and this paragraph are
  181. X * duplicated in all such forms and that any documentation,
  182. X * advertising materials, and other materials related to such
  183. X * distribution and use acknowledge that the software was developed
  184. X * by Southwest Research Institute.  The name of Southwest Research
  185. X * Institute may not be used to endorse or promote products derived
  186. X * from this software without specific prior written permission.
  187. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  188. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  189. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  190. X */
  191. X
  192. X#ifndef lint
  193. Xstatic char     sccsid[] = "@(#)dg.c    1.5 6/29/89             Copyright (c) 1989\
  194. X by Southwest Research Institute, San Antonio, Texas";
  195. X#endif
  196. X
  197. X#include <stdio.h>
  198. X#include <signal.h>
  199. X#include <sgtty.h>
  200. X#include <sys/wait.h>
  201. X#include <sys/types.h>
  202. X#include <sys/socket.h>
  203. X#include <netdb.h>
  204. X
  205. X#define    queue_char( c )    *end_of_queue++ = c 
  206. X#define    flush_the_queue()    {\
  207. Xwrite(1, write_queue, end_of_queue - write_queue);\
  208. Xend_of_queue = write_queue;\
  209. X}
  210. X
  211. Xchar buf1[256];
  212. Xchar buf0[256];
  213. X
  214. Xchar    write_queue[2048];
  215. Xchar    motion_buf[16];
  216. Xchar    *end_of_queue;
  217. X
  218. Xint master, slave, child, pid;
  219. Xchar linec, linen;
  220. X
  221. Xstruct baud_tab {
  222. X    char    *baud_string;
  223. X    int    baud_rate;
  224. X} baud_tab[] = {
  225. X    "50",    B50,
  226. X    "75",    B75,
  227. X    "110",    B110,
  228. X    "134",    B134,
  229. X    "150",    B150,
  230. X    "200",    B200,
  231. X    "300",    B300,
  232. X    "600",    B600,
  233. X    "1200", B1200,
  234. X    "1800", B1800,
  235. X    "2400", B2400,
  236. X    "4800",    B4800,
  237. X    "9600",    B9600,
  238. X    "19200",    EXTA,
  239. X    NULL,    0
  240. X};
  241. X
  242. Xstruct sgttyb tmode;
  243. Xint savemode;
  244. Xint fd, tflag;
  245. Xchar    *host;
  246. X
  247. Xdone()
  248. X{
  249. X     union wait status;
  250. X
  251. X     if (wait3(&status, WNOHANG, 0) == 0)
  252. X      return;
  253. X
  254. X     ioctl (0, TIOCNXCL, &tmode);
  255. X     tmode.sg_flags = savemode;
  256. X     ioctl (0, TIOCSETP, &tmode);
  257. X     kill(pid, SIGTERM);
  258. X     kill(0, SIGTERM);
  259. X     exit(0);
  260. X
  261. X}
  262. X
  263. X
  264. Xmain( argc, argv)
  265. Xint    argc;
  266. Xchar    **argv;
  267. X{
  268. X     int    baud = B9600;
  269. X     int    is_host = 0;
  270. X
  271. X     end_of_queue = write_queue;
  272. X
  273. X     if ((argc > 3) || (argc < 2) ) {
  274. X      fprintf(stderr, "dg /dev/tty?|hostname  [buad]\n");
  275. X      fprintf(stderr, "type ^~ to exit\n");
  276. X      exit(1);
  277. X     }
  278. X
  279. X     host = argv[1];
  280. X     if (gethostbyname(host) != NULL)
  281. X      is_host = 1;
  282. X
  283. X     if (is_host) {
  284. X      setup_master();
  285. X      signal(SIGCHLD, done);
  286. X      fd = master;
  287. X     } else {
  288. X      fd = open(*(++argv), 2);
  289. X      argc--;
  290. X
  291. X      if (argc > 1) {
  292. X           baud = find_baud(*(++argv));
  293. X      }
  294. X
  295. X      if (fd < 0) {
  296. X           fprintf(stderr, "dg: can't open the line to the DG or find a host\n");
  297. X           exit(1);
  298. X      }
  299. X     }
  300. X     ioctl (fd,TIOCGETP, &tmode);
  301. X     tmode.sg_flags = RAW + TANDEM;
  302. X     tmode.sg_ispeed = baud;
  303. X     tmode.sg_ospeed = baud;
  304. X     ioctl (fd,TIOCSETP, &tmode);
  305. X     ioctl (fd,TIOCEXCL, &tmode);
  306. X
  307. X     ioctl (0,TIOCGETP, &tmode);
  308. X     savemode = tmode.sg_flags;
  309. X     tmode.sg_flags = RAW;
  310. X     ioctl (0,TIOCSETP, &tmode);
  311. X
  312. X     pid = fork();
  313. X     if (pid) {
  314. X      write(fd, buf1, strlen(buf1));
  315. X      writer();
  316. X     } else {
  317. X      if (is_host) {
  318. X           if (fork()) {
  319. X            reader();
  320. X           } else {
  321. X            start_telnet();
  322. X           }
  323. X      } else {
  324. X           reader();
  325. X      }
  326. X     }
  327. X}
  328. X
  329. Xqueue_string(string)
  330. Xchar    *string;
  331. X{
  332. X    register char    *cp;
  333. X
  334. X    cp = string;
  335. X    while (*cp)
  336. X        *end_of_queue++ = *cp++;
  337. X}
  338. X
  339. Xfind_baud(string)
  340. Xchar *string;
  341. X{
  342. X    struct baud_tab    *btp;
  343. X
  344. X    btp = baud_tab;
  345. X
  346. X    while(btp->baud_string != NULL) {
  347. X        if (strcmp (string, btp->baud_string) == 0)
  348. X            return(btp->baud_rate);
  349. X        btp++;
  350. X    }
  351. X    fprintf(stderr, "dg: unknown baud rate\n");
  352. X    fprintf(stderr, "known baud rates are:\n");
  353. X
  354. X    btp = baud_tab;
  355. X    while(btp->baud_string != NULL) {
  356. X        fprintf(stderr, "\t%s\n", btp->baud_string);
  357. X        btp++;
  358. X    }
  359. X    exit(1);
  360. X}
  361. X
  362. Xstart_telnet()
  363. X{
  364. X     int t;
  365. X     char *term, *getenv(), *telnet, *tail, *rindex();
  366. X
  367. X     telnet = "/usr/ucb/telnet";
  368. X     tail = "telnet";
  369. X     
  370. X     if ((t = open("/dev/tty", 2)) >= 0) {
  371. X      ioctl(t, TIOCNOTTY, (char *)0);
  372. X      close(t);
  373. X     }
  374. X     setup_slave();
  375. X     close(master);
  376. X     dup2(slave, 0);
  377. X     dup2(slave, 1);
  378. X     dup2(slave, 2);
  379. X     close(slave);
  380. X     execl(telnet, tail, host, (char *)0);
  381. X     perror(telnet);
  382. X     fail();
  383. X}
  384. X
  385. Xfail()
  386. X{
  387. X     kill(0, SIGTERM);
  388. X     exit(0);
  389. X}
  390. X
  391. Xsetup_master()
  392. X{
  393. X     char line[11];
  394. X
  395. X     for (linec = 'p'; linec <= 's'; linec++) {
  396. X      sprintf(line, "/dev/pty%c0", linec);
  397. X      if (access(line, 0) != 0)
  398. X           break;
  399. X      for (linen = 0; linen < 16; linen++) {
  400. X           sprintf(line, "/dev/pty%c%1x", linec, linen);
  401. X           master = open(line, 2);
  402. X           if (master >= 0) {
  403. X            return;
  404. X           }
  405. X      }
  406. X     }
  407. X     fprintf(stderr, "Can't find a pty\n");
  408. X     fail();
  409. X}
  410. X
  411. Xsetup_slave()
  412. X{
  413. X     char line[11];
  414. X
  415. X     sprintf(line, "/dev/tty%c%1x", linec, linen);
  416. X     slave = open(line, 2);
  417. X     if (slave < 0) {
  418. X      perror(line);
  419. X      fail();
  420. X     }
  421. X}
  422. X
  423. Xreader()
  424. X{
  425. X     register int    count;
  426. X     register int    index;
  427. X     register int    row, col;
  428. X     register char    *cp, *end, c;
  429. X
  430. X     for(;;) {
  431. X      count = read(fd, buf0, 256);
  432. X      end = buf0 + count;
  433. X      for (cp = buf0; cp < end; cp++) {
  434. X           c = *cp & 0177;
  435. X           switch(c) {
  436. X           case '\000':
  437. X            break;
  438. X           case '\003':
  439. X            break;
  440. X           case '\005':    /* read cursor position - this is a real hack */
  441. X            queue_string("\033[1;1H");
  442. X            write(fd, "\037\000\000", 3);
  443. X            break;
  444. X           case '\031':    /* bc=^y */
  445. X            queue_string("\010");
  446. X            break;
  447. X           case '\020':    /* cm=4^p%r%.%. */
  448. X            cp++;
  449. X            if (cp >= end) {
  450. X             count = read(fd, buf0, 1);
  451. X             end = buf0 + count;
  452. X             cp = buf0;
  453. X            }
  454. X            col = *cp & 0177;
  455. X            cp++;
  456. X            if (cp >= end) {
  457. X             count = read(fd, buf0, 1);
  458. X             end = buf0 + count;
  459. X             cp = buf0;
  460. X            }
  461. X            row = *cp & 0177;
  462. X            col++;
  463. X            row++;
  464. X            sprintf(motion_buf, "\033[%d;%dH", row, col);
  465. X            queue_string(motion_buf);
  466. X            break;
  467. X           case '\036':    /* extended commands */
  468. X            cp++;
  469. X            if (cp >= end) {
  470. X             count = read(fd, buf0, 1);
  471. X             end = buf0 + count;
  472. X             cp = buf0;
  473. X            }
  474. X            switch(*cp) {
  475. X            case '\105':    /* reverse video off */
  476. X             queue_string("\033[m");
  477. X             break;
  478. X            case '\104':    /* reverse video on */
  479. X             queue_string("\033[7m");
  480. X             break;
  481. X            default:
  482. X             break;
  483. X            }
  484. X            break;
  485. X           case '\027':    /* up=^w */
  486. X            queue_string("\033[A");
  487. X            break;
  488. X           case '\013':    /* ce=^k */
  489. X            queue_string("\033[K");
  490. X            break;
  491. X           case '\024':    /* us=^t */
  492. X            /* start underscore */
  493. X            queue_string("\033[4m");
  494. X            break;
  495. X           case '\025':    /* ue=^u */
  496. X            /* end undersore */
  497. X            queue_string("\033[m");
  498. X            break;
  499. X           case '\034':    /* so=^\ */
  500. X            queue_string("\033[m");
  501. X            break;
  502. X           case '\035':    /* se=^] */
  503. X            queue_string("\033[1m");
  504. X            break;
  505. X           case '\030':    /* kr=^x */
  506. X            queue_string("\033[C");
  507. X            break;
  508. X           case '\032':    /* kd=^z */
  509. X            queue_string("\033[B");
  510. X            break;
  511. X           case '\010':    /* kh=^h */
  512. X            queue_string("\033[1;1H");
  513. X            break;
  514. X           case '\022':    /* is=^r */
  515. X            break;
  516. X           case '\012':    /* nl */
  517. X            queue_string("\n\r");
  518. X            break;
  519. X           default:
  520. X            queue_char((int)c);
  521. X           }
  522. X      }
  523. X      flush_the_queue();
  524. X     }
  525. X
  526. X}
  527. X
  528. Xwriter()
  529. X{
  530. X     register int    count;
  531. X     register int    index;
  532. X     register int    row, col;
  533. X     register char    *cp, *end, c;
  534. X
  535. X     for(;;) {
  536. X      count = read(0, buf1, 256);
  537. X      index = 0;
  538. X      while (index < count) {
  539. X           if (tflag && (buf1[index] == '~') ) {
  540. X             kill(pid, SIGTERM);
  541. X            ioctl (0, TIOCNXCL, &tmode);
  542. X            tmode.sg_flags = savemode;
  543. X            ioctl (0, TIOCSETP, &tmode);
  544. X            exit(0);;
  545. X           } else {
  546. X            tflag = 0;
  547. X           }
  548. X           if (buf1[index] == '^')
  549. X            tflag = 1;
  550. X           ++index;
  551. X      }
  552. X      write(fd, buf1, count);
  553. X     }
  554. X}
  555. X
  556. X
  557. SHAR_EOF
  558. if test 7795 -ne "`wc -c 'dg.c'`"
  559. then
  560.     echo shar: error transmitting "'dg.c'" '(should have been 7795 characters)'
  561. fi
  562. echo shar: extracting "'dgtool.1'" '(1773 characters)'
  563. if test -f 'dgtool.1'
  564. then
  565.     echo shar: over-writing existing file "'dgtool.1'"
  566. fi
  567. sed 's/^X//' << \SHAR_EOF > 'dgtool.1'
  568. X.\" Copyright (c) 1989 Southwest Research Institute
  569. X.\" All rights reserved.
  570. X.\"
  571. X.\" Redistribution and use in source and binary forms are permitted
  572. X.\" provided that the above copyright notice and this paragraph are
  573. X.\" duplicated in all such forms and that any documentation,
  574. X.\" advertising materials, and other materials related to such
  575. X.\" distribution and use acknowledge that the software was developed
  576. X.\" by Southwest Research Institute.  The name of Southwest Research
  577. X.\" Institute may not be used to endorse or promote products derived
  578. X.\" from this software without specific prior written permission.
  579. X.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  580. X.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  581. X.\" WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  582. X.\"
  583. X.TH DGTOOL 1L "30 June 1989"
  584. X.SH NAME
  585. Xdgtool \- provide a Data General terminal emulation in a window
  586. X.SH SYNOPSIS
  587. X.B dgtool
  588. X.I serial line
  589. X[
  590. X.I baud rate
  591. X]
  592. X[
  593. X.I window options
  594. X]
  595. X.SH DESCRIPTION
  596. X.I dgtool
  597. Xprovides a window with a terminal emulation and a serial line or telnet
  598. Xinterface for a Data General system.
  599. XThe DG function keys F1\-F15 are replaced by F1\-F9 and R1\-R6
  600. Xon the Sun-3 keyboard.
  601. XHome is generated by the R11 key and R7, R9, R13, R15 are the
  602. X``C'' function keys.
  603. XThe cursor motion emulation and serial line access is handled
  604. Xby
  605. X.IR dg (1L).
  606. X.SH OPTIONS
  607. X.LP
  608. XThe first argument of
  609. X.I dgtool
  610. Xspecifies which serial line or host to use when accessing the DG.
  611. XThe second argument is optional and specifies the baud rate to
  612. Xbe used in communicating with the DG.
  613. X.I dgtool
  614. Xwill also accept the standard window arguments, see
  615. X.IR suntools (1).
  616. X.SH "SEE ALSO"
  617. Xsuntools(1), dg(1L)
  618. X.SH AUTHOR
  619. XKeith S. Pickens, Southwest Research Institute
  620. SHAR_EOF
  621. if test 1773 -ne "`wc -c 'dgtool.1'`"
  622. then
  623.     echo shar: error transmitting "'dgtool.1'" '(should have been 1773 characters)'
  624. fi
  625. echo shar: extracting "'dgtool.c'" '(9201 characters)'
  626. if test -f 'dgtool.c'
  627. then
  628.     echo shar: over-writing existing file "'dgtool.c'"
  629. fi
  630. sed 's/^X//' << \SHAR_EOF > 'dgtool.c'
  631. X/*
  632. X * Copyright (c) 1989 Southwest Research Institute
  633. X * All rights reserved.
  634. X *
  635. X * Redistribution and use in source and binary forms are permitted
  636. X * provided that the above copyright notice and this paragraph are
  637. X * duplicated in all such forms and that any documentation,
  638. X * advertising materials, and other materials related to such
  639. X * distribution and use acknowledge that the software was developed
  640. X * by Southwest Research Institute.  The name of Southwest Research
  641. X * Institute may not be used to endorse or promote products derived
  642. X * from this software without specific prior written permission.
  643. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  644. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  645. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  646. X */
  647. X
  648. X#ifndef lint
  649. Xstatic char     sccsid[] = "@(#)dgtool.c    1.9    6/29/89        Copyright (c) 1989\
  650. X by Southwest Research Institute, San Antonio, Texas";
  651. X#endif
  652. X
  653. X/* 
  654. X * path name for `dg' - this is system dependent
  655. X */
  656. X
  657. X
  658. X#define DG    "/usr/local/bin/dg"
  659. X
  660. X#include <stdio.h>
  661. X#include <strings.h>
  662. X#include <suntool/sunview.h>
  663. X#include <suntool/panel.h>
  664. X#include <suntool/canvas.h>
  665. X#include <sunwindow/win_cursor.h>
  666. X#include <suntool/tty.h>
  667. X#include <sundev/kbio.h>
  668. X#include <sundev/kbd.h>
  669. X#include <sgtty.h>
  670. X#include <sys/types.h>
  671. X#include <sys/socket.h>
  672. X#include <netdb.h>
  673. X
  674. X#define NUM_KEYS_TO_SAVE    8
  675. X
  676. XFrame    base_frame;
  677. XTty    tty_win;
  678. Xstatic void    input_proc();
  679. Xstatic Notify_value    my_tty_interposer();
  680. Xstatic Notify_value    my_destroy_interposer();
  681. Xstatic int    kb_fd;
  682. X
  683. Xstatic struct kiockey save_keys[NUM_KEYS_TO_SAVE] = {
  684. X                    {0, 0x45, 0, ""}, /* up arrow */
  685. X                    {0, 0x5d, 0, ""}, /* right arrow */
  686. X                    {0, 0x5b, 0, ""}, /*left arrow */
  687. X                    {0, 0x71, 0, ""}, /*down arrow */
  688. X                    {SHIFTMASK, 0x45, 0, ""}, /* up arrow */
  689. X                    {SHIFTMASK, 0x5d, 0, ""}, /* right arrow */
  690. X                    {SHIFTMASK, 0x5b, 0, ""}, /*left arrow */
  691. X                    {SHIFTMASK, 0x71, 0, ""}, /*down arrow */
  692. X};
  693. X
  694. Xstatic void    get_keys();
  695. Xstatic void    fix_keys();
  696. Xstatic void    reset_keys();
  697. Xstatic void    do_key();
  698. Xstatic void    check_baud();
  699. Xstatic void    do_c_key();
  700. X
  701. X/* support an icon */
  702. Xstatic short    icon_image[] = {
  703. X#include    "dgtool.icon"
  704. X};
  705. X
  706. XDEFINE_ICON_FROM_IMAGE(dgtool_icon, icon_image);
  707. X
  708. Xstruct baud_tab {
  709. X    char    *baud_string;
  710. X    int baud_rate;
  711. X} baud_tab[] = {
  712. X    "50",   B50,
  713. X    "75",   B75,
  714. X    "110",  B110,
  715. X    "134",  B134,
  716. X    "150",  B150,
  717. X    "200",  B200,
  718. X    "300",  B300,
  719. X    "600",  B600,
  720. X    "1200", B1200,
  721. X    "1800", B1800,
  722. X    "2400", B2400,
  723. X    "4800", B4800,
  724. X    "9600", B9600,
  725. X    "19200",    EXTA,
  726. X    NULL,   0
  727. X};
  728. X
  729. Xmain(argc, argv)
  730. Xint             argc;
  731. Xchar          **argv;
  732. X{
  733. X    int    test_fd;
  734. X
  735. X    kb_fd = open("/dev/kbd", 2);
  736. X    if (kb_fd < 0) {
  737. X        fprintf(stderr, "dgtool: keyboard open failed\n");
  738. X        exit(1);
  739. X    }
  740. X
  741. X    base_frame = window_create(0, FRAME,
  742. X                   WIN_ROWS,    25,
  743. X                   WIN_COLUMNS,    80,
  744. X                   FRAME_LABEL, "dgtool",
  745. X                   FRAME_ICON, &dgtool_icon,
  746. X                   FRAME_ARGC_PTR_ARGV, &argc, argv,
  747. X                   0);
  748. X
  749. X    if ((argc > 3) || (argc < 2)) {
  750. X        fprintf(stderr, "dgtool /dev/tty?|host [baud] [window args]\n");
  751. X        exit(1);
  752. X    }
  753. X
  754. X    if ( ((test_fd = open(argv[1], 2)) < 0 ) && (gethostbyname(argv[0]) != NULL) ) {
  755. X        fprintf(stderr, "dgtool: can't open the line to the DG or find a host\n");
  756. X        exit(1);
  757. X    } else {
  758. X         if (test_fd >= 0)
  759. X        close(test_fd);
  760. X    }
  761. X    if (argc == 3) {
  762. X        check_baud(argv[2]);
  763. X    }
  764. X
  765. X    argv[0] = DG;
  766. X
  767. X    tty_win = window_create(base_frame, TTY, TTY_ARGV, argv, 0);
  768. X
  769. X    window_set(tty_win, WIN_CONSUME_KBD_EVENTS,
  770. X            WIN_ASCII_EVENTS,
  771. X            WIN_RIGHT_KEYS,
  772. X            WIN_TOP_KEYS,
  773. X            0,
  774. X            0);
  775. X    window_set(tty_win, WIN_IGNORE_KBD_EVENT, WIN_UP_EVENTS, 0);
  776. X
  777. X    notify_interpose_destroy_func(base_frame, my_destroy_interposer);
  778. X    notify_interpose_event_func(tty_win, my_tty_interposer, NOTIFY_SAFE);
  779. X
  780. X    window_main_loop(base_frame);
  781. X    exit(0);
  782. X}
  783. X
  784. X
  785. X
  786. Xstatic void
  787. Xget_keys()
  788. X{
  789. X     register int i;
  790. X
  791. X     for( i = 0; i < NUM_KEYS_TO_SAVE; i++) {
  792. X      if (ioctl(kb_fd, KIOCGETKEY, &save_keys[i]) < 0) {
  793. X           fprintf(stderr, "dgtool: getkeys - kb ioctl failed\n");
  794. X           exit(1);
  795. X      }
  796. X     }
  797. X}
  798. X
  799. Xstatic void
  800. Xreset_keys()
  801. X{
  802. X     register int i;
  803. X
  804. X     for( i = 0; i < NUM_KEYS_TO_SAVE; i++) {
  805. X      if (ioctl(kb_fd, KIOCSETKEY, &save_keys[i]) < 0) {
  806. X           fprintf(stderr, "dgtool: reset_keys - kb ioctl failed\n");
  807. X           exit(1);
  808. X      }
  809. X     }
  810. X}
  811. X
  812. Xstatic void
  813. Xfix_keys()
  814. X{
  815. X    struct kiockey    tmp_key;
  816. X
  817. X    tmp_key = save_keys[0];    /* up arrow */
  818. X    tmp_key.kio_entry = 027;
  819. X    if (ioctl(kb_fd, KIOCSETKEY, &tmp_key) < 0) {
  820. X        fprintf(stderr, "dgtool: kb ioctl failed\n");
  821. X        exit(1);
  822. X    }
  823. X
  824. X    tmp_key = save_keys[4];    /* shifted up arrow */
  825. X    strcpy(tmp_key.kio_string, "\036\027");
  826. X    if (ioctl(kb_fd, KIOCSETKEY, &tmp_key) < 0) {
  827. X        fprintf(stderr, "dgtool: kb ioctl failed\n");
  828. X        exit(1);
  829. X    }
  830. X
  831. X    tmp_key = save_keys[1];    /* right arrow */
  832. X    tmp_key.kio_entry = 030;
  833. X    if (ioctl(kb_fd, KIOCSETKEY, &tmp_key) < 0) {
  834. X        fprintf(stderr, "dgtool: kb ioctl failed\n");
  835. X        exit(1);
  836. X    }
  837. X    tmp_key = save_keys[5];    /* shifted right arrow */
  838. X    strcpy(tmp_key.kio_string, "\036\030");
  839. X    if (ioctl(kb_fd, KIOCSETKEY, &tmp_key) < 0) {
  840. X        fprintf(stderr, "dgtool: kb ioctl failed\n");
  841. X        exit(1);
  842. X    }
  843. X
  844. X    tmp_key = save_keys[2];    /* left arrow */
  845. X    tmp_key.kio_entry = 031;
  846. X    if (ioctl(kb_fd, KIOCSETKEY, &tmp_key) < 0) {
  847. X        fprintf(stderr, "dgtool: kb ioctl failed\n");
  848. X        exit(1);
  849. X    }
  850. X    tmp_key = save_keys[6];    /* shifted left arrow */
  851. X    strcpy(tmp_key.kio_string, "\036\031");
  852. X    if (ioctl(kb_fd, KIOCSETKEY, &tmp_key) < 0) {
  853. X        fprintf(stderr, "dgtool: kb ioctl failed\n");
  854. X        exit(1);
  855. X    }
  856. X
  857. X    tmp_key = save_keys[3];    /* down arrow */
  858. X    tmp_key.kio_entry = 032;
  859. X    if (ioctl(kb_fd, KIOCSETKEY, &tmp_key) < 0) {
  860. X        fprintf(stderr, "dgtool: kb ioctl failed\n");
  861. X        exit(1);
  862. X    }
  863. X    tmp_key = save_keys[7];    /* shifted down arrow */
  864. X    strcpy(tmp_key.kio_string, "\036\032");
  865. X    if (ioctl(kb_fd, KIOCSETKEY, &tmp_key) < 0) {
  866. X        fprintf(stderr, "dgtool: kb ioctl failed\n");
  867. X        exit(1);
  868. X    }
  869. X
  870. X}
  871. X
  872. Xstatic Notify_value
  873. Xmy_destroy_interposer(frame, status)
  874. XFrame    frame;
  875. XDestroy_status    status;
  876. X{
  877. X    if (status == DESTROY_CLEANUP) {
  878. X        reset_keys();
  879. X    }
  880. X    return(notify_next_destroy_func(frame, status));
  881. X}
  882. X
  883. Xstatic Notify_value
  884. Xmy_tty_interposer(frame, event, arg, type)
  885. XFrame    frame;
  886. XEvent    *event;
  887. XNotify_arg    arg;
  888. XNotify_event_type    type;
  889. X{
  890. X    register int    input;
  891. X    register int    shift, ctrl;
  892. X    char    baby_buffer;    /* for arrow keys */
  893. X    Notify_value    value;
  894. X
  895. X    input = event_id(event);
  896. X
  897. X    if (input == KBD_USE) {
  898. X        get_keys();
  899. X        fix_keys();
  900. X    }
  901. X
  902. X    if (input == KBD_DONE) {
  903. X        reset_keys();
  904. X    }
  905. X
  906. X    if ((event_is_key_top(event)) || (event_is_key_right(event)) ) {
  907. X
  908. X        if ( event_ctrl_is_down(event)) {
  909. X            ctrl = 1;
  910. X        } else {
  911. X            ctrl = 0;
  912. X        }
  913. X
  914. X        if ( event_shift_is_down(event)) {
  915. X            shift = 1;
  916. X        } else {
  917. X            shift = 0;
  918. X        }
  919. X
  920. X        switch(input) {
  921. X        /*
  922. X         * function keys
  923. X         */
  924. X        case KEY_RIGHT(6):
  925. X            do_key(0160, shift, ctrl);
  926. X            break;
  927. X        case KEY_TOP(1):
  928. X            do_key(0161, shift, ctrl);
  929. X            break;
  930. X        case KEY_TOP(2):
  931. X            do_key(0162, shift, ctrl);
  932. X            break;
  933. X        case KEY_TOP(3):
  934. X            do_key(0163, shift, ctrl);
  935. X            break;
  936. X        case KEY_TOP(4):
  937. X            do_key(0164, shift, ctrl);
  938. X            break;
  939. X        case KEY_TOP(5):
  940. X            do_key(0165, shift, ctrl);
  941. X            break;
  942. X        case KEY_TOP(6):
  943. X            do_key(0166, shift, ctrl);
  944. X            break;
  945. X        case KEY_TOP(7):
  946. X            do_key(0167, shift, ctrl);
  947. X            break;
  948. X        case KEY_TOP(8):
  949. X            do_key(0170, shift, ctrl);
  950. X            break;
  951. X        case KEY_TOP(9):
  952. X            do_key(0171, shift, ctrl);
  953. X            break;
  954. X        case KEY_RIGHT(1):
  955. X            do_key(0172, shift, ctrl);
  956. X            break;
  957. X        case KEY_RIGHT(2):
  958. X            do_key(0173, shift, ctrl);
  959. X            break;
  960. X        case KEY_RIGHT(3):
  961. X            do_key(0174, shift, ctrl);
  962. X            break;
  963. X        case KEY_RIGHT(4):
  964. X            do_key(0175, shift, ctrl);
  965. X            break;
  966. X        case KEY_RIGHT(5):
  967. X            do_key(0176, shift, ctrl);
  968. X            break;
  969. X        /*
  970. X         * home
  971. X         */
  972. X        case KEY_RIGHT(11):
  973. X            baby_buffer = 010;
  974. X            ttysw_input(tty_win, &baby_buffer, 1);
  975. X            break;
  976. X        /*
  977. X         * "c" keys
  978. X         */
  979. X        case KEY_RIGHT(7):
  980. X            do_c_key(0134, shift);
  981. X            break;
  982. X        case KEY_RIGHT(9):
  983. X            do_c_key(0135, shift);
  984. X            break;
  985. X        case KEY_RIGHT(13):
  986. X            do_c_key(0136, shift);
  987. X            break;
  988. X        case KEY_RIGHT(15):
  989. X            do_c_key(0137, shift);
  990. X            break;
  991. X        default:
  992. X            break;
  993. X        }
  994. X        return(NOTIFY_DONE);
  995. X    }
  996. X    value = notify_next_event_func(frame, event, arg, type);
  997. X    return(value);
  998. X}
  999. X
  1000. Xstatic void
  1001. Xdo_key(code, shift, ctrl)
  1002. Xint    code, shift, ctrl;
  1003. X{
  1004. X    register char    out_code;
  1005. X    static char    buffer[2] = "\036";
  1006. X
  1007. X
  1008. X    if (shift && ctrl) {
  1009. X        out_code = code - 0120;
  1010. X    } else if (shift) {
  1011. X        out_code = code - 020;
  1012. X    } else if (ctrl) {
  1013. X        out_code = code - 0100;
  1014. X    } else {
  1015. X        out_code = code;
  1016. X    }
  1017. X    buffer[1] = out_code;
  1018. X    ttysw_input(tty_win, buffer, 2);
  1019. X}
  1020. X
  1021. Xstatic void
  1022. Xcheck_baud(string)
  1023. Xchar *string;
  1024. X{
  1025. X    struct baud_tab *btp;
  1026. X    btp = baud_tab;
  1027. X    while(btp->baud_string != NULL) {
  1028. X        if (strcmp (string, btp->baud_string) == 0)
  1029. X            return;
  1030. X        btp++;
  1031. X    }
  1032. X    fprintf(stderr, "dgtool: unknown baud rate\n");
  1033. X    fprintf(stderr, "known baud rates are:\n");
  1034. X    btp = baud_tab;
  1035. X    while(btp->baud_string != NULL) {
  1036. X        fprintf(stderr, "\t%s\n", btp->baud_string);
  1037. X        btp++;
  1038. X    }
  1039. X    exit(1);
  1040. X}
  1041. X
  1042. Xstatic void
  1043. Xdo_c_key(code, shift)
  1044. Xint    code, shift;
  1045. X{
  1046. X    register char    out_code;
  1047. X    static char    buffer[2] = "\036";
  1048. X
  1049. X
  1050. X    if (shift) {
  1051. X        out_code = code - 04;
  1052. X    } else {
  1053. X        out_code = code;
  1054. X    }
  1055. X    buffer[1] = out_code;
  1056. X    ttysw_input(tty_win, buffer, 2);
  1057. X}
  1058. SHAR_EOF
  1059. if test 9201 -ne "`wc -c 'dgtool.c'`"
  1060. then
  1061.     echo shar: error transmitting "'dgtool.c'" '(should have been 9201 characters)'
  1062. fi
  1063. echo shar: extracting "'dgtool.icon'" '(2838 characters)'
  1064. if test -f 'dgtool.icon'
  1065. then
  1066.     echo shar: over-writing existing file "'dgtool.icon'"
  1067. fi
  1068. sed 's/^X//' << \SHAR_EOF > 'dgtool.icon'
  1069. X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
  1070. X * @(#)dgtool.i    1.1 6/28/89 Copyright (c) 1989 by Southwest Research Institute, San Antonio, TX
  1071. X *
  1072. X * Copyright (c) 1989 Southwest Research Institute
  1073. X * All rights reserved.
  1074. X *
  1075. X * Redistribution and use in source and binary forms are permitted
  1076. X * provided that the above copyright notice and this paragraph are
  1077. X * duplicated in all such forms and that any documentation,
  1078. X * advertising materials, and other materials related to such
  1079. X * distribution and use acknowledge that the software was developed
  1080. X * by Southwest Research Institute.  The name of Southwest Research
  1081. X * Institute may not be used to endorse or promote products derived
  1082. X * from this software without specific prior written permission.
  1083. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  1084. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  1085. X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1086. X */
  1087. X    0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  1088. X    0xC000,0x0000,0x0000,0x0003,0xC000,0x0039,0xCE00,0x0003,
  1089. X    0xC00F,0x8039,0xCE02,0x2003,0xC892,0x404A,0x5251,0xC7C3,
  1090. X    0xD740,0x004A,0x5220,0x8923,0xC200,0x01CE,0x7380,0x0003,
  1091. X    0xC030,0x0F4A,0x50F0,0x0003,0xC000,0xF54A,0x50AF,0x0413,
  1092. X    0xC003,0x5B4A,0x50DA,0xC3E3,0xD405,0xB57A,0x4CAD,0xA083,
  1093. X    0xC81B,0x554A,0x42AA,0xD803,0xC035,0x5B4A,0x42DA,0xAC2B,
  1094. X    0xC055,0xB54A,0x42AD,0xAA13,0xC05B,0x554A,0x52AA,0xDA03,
  1095. X    0xC0B5,0x5BCE,0x73DA,0xAD03,0xC1D5,0xBF4A,0x52FD,0xAB83,
  1096. X    0xC35B,0xF06B,0x9C0F,0xDAC3,0xC1FF,0x006B,0x9C00,0xFF83,
  1097. X    0xC049,0x0000,0x0024,0x8A03,0xC063,0x0000,0x0018,0xA203,
  1098. X    0xD145,0x1111,0x0000,0xC68B,0xD151,0x1111,0x0000,0x928B,
  1099. X    0xFBC9,0x3BBB,0x0880,0x8BDF,0xD163,0x1111,0x0500,0xA28B,
  1100. X    0xFFFF,0xFFFF,0x0201,0xC7FF,0xD541,0xD555,0x0201,0x92AB,
  1101. X    0xD545,0xD555,0x0001,0x8AAB,0xFBC5,0xBBBB,0x0001,0xA3DF,
  1102. X    0xD545,0xD555,0x0001,0xC6AB,0xD545,0xD555,0x0221,0x92AB,
  1103. X    0xFBC5,0xBBBB,0x05D1,0x8BDF,0xD545,0x5555,0x0080,0xFEAB,
  1104. X    0xD545,0x5555,0x0000,0x82AB,0xFBCD,0xBBBB,0x0001,0x9BDF,
  1105. X    0xD555,0x5555,0x0000,0xAAAB,0xD555,0x5555,0x0000,0xAAAB,
  1106. X    0xFBD5,0xBBBB,0x0001,0xABDF,0xD555,0x5555,0x0000,0xAAAB,
  1107. X    0xD555,0x555F,0x0000,0xAAAB,0xFBD5,0xBBBB,0x0001,0xABDF,
  1108. X    0xD555,0x555F,0x0000,0xAAAB,0xD54D,0x5555,0x0000,0x9AAB,
  1109. X    0xFBC1,0xBBBB,0x0001,0x8BDF,0xD57F,0x5555,0x0800,0xAAAB,
  1110. X    0xD545,0x5555,0x1010,0xAAAB,0xFBD1,0xBBBB,0x1019,0xABDF,
  1111. X    0xD549,0x5555,0x133C,0xAAAB,0xD563,0x5555,0x17F8,0xAAAB,
  1112. X    0xFBC5,0xBBBB,0x17F1,0x93DF,0xD551,0x5555,0x0FFC,0x82AB,
  1113. X    0xD549,0x5555,0x0EF2,0xFEAB,0xFBE3,0xBBBB,0x0E61,0xA3DF,
  1114. X    0xD545,0xD555,0x0C61,0xC6AB,0xD551,0xD555,0x0821,0x92AB,
  1115. X    0xFBC9,0xBBBB,0x0821,0x8BDF,0xD563,0xD555,0x0411,0xA2AB,
  1116. X    0xD545,0xD555,0x0001,0xC6AB,0xFFD1,0xFFFF,0x0001,0x93FF,
  1117. X    0xC07F,0x0000,0x0000,0xFE03,0xC000,0x0000,0x0000,0x0003,
  1118. X    0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF
  1119. SHAR_EOF
  1120. if test 2838 -ne "`wc -c 'dgtool.icon'`"
  1121. then
  1122.     echo shar: error transmitting "'dgtool.icon'" '(should have been 2838 characters)'
  1123. fi
  1124. #    End of shell archive
  1125. exit 0
  1126.